package com.enjoy.solr.queryParser;

import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.Query;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.QParser;
import org.apache.solr.search.QParserPlugin;
import org.apache.solr.search.SolrQueryParser;
import org.apache.solr.search.SyntaxError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class PageQparserPlugin extends QParserPlugin {

	public static final String NAME = "pagePlugin";
			
	@Override
	public void init(NamedList args) {
	}

	@Override
	public QParser createParser(String qstr, SolrParams localParams,
			SolrParams params, SolrQueryRequest req) {
		return new PageQparser(qstr, localParams, params, req);
	}

    class PageQparser extends QParser {


        public PageQparser(String qstr, SolrParams localParams, SolrParams params,
                           SolrQueryRequest req) {
            super(qstr, localParams, params, req);
        }

        @Override
        public Query parse() throws SyntaxError {

            // 最终打分采用分数最大域的打分，而不是相加
            DisjunctionMaxQuery mbq = new DisjunctionMaxQuery(0.0f);

            return mbq;

        }
    }

}
